/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */
package com.yami.shop.distribution.platform.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.distribution.common.model.DistributionUserWalletBill;
import com.yami.shop.distribution.common.service.DistributionUserWalletBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author xwc
 * @date 2019-04-29 16:39:13
 */
@RestController
@RequestMapping("/distribution/distributionUserWalletBill")
@Api(tags = "平台端分销员钱包流水接口")
public class DistributionUserWalletBillController {

    @Autowired
    private DistributionUserWalletBillService distributionUserWalletBillService;

    @GetMapping("/page")
    @ApiOperation(value = "分页获取分销员钱包流水列表")
    public ServerResponseEntity<IPage<DistributionUserWalletBill>> getDistributionUserWalletBillPage(PageParam<DistributionUserWalletBill> page,
                                                                                               DistributionUserWalletBill distributionUserWalletBill) {
        return ServerResponseEntity.success(distributionUserWalletBillService.page(page, new LambdaQueryWrapper<DistributionUserWalletBill>()));
    }

    @GetMapping("/pageAndUser")
    @ApiOperation(value = "分页查询(携带UserVO)")
    @ApiImplicitParam(name = "userMobile", value = "分销员手机号码", dataType = "String")
    public ServerResponseEntity<IPage<DistributionUserWalletBill>> getDistributionUserWalletBillAndUserPage(PageParam page, String userMobile) {
        return ServerResponseEntity.success(distributionUserWalletBillService.getDistributionUserWalletBillAndUserPage(page, userMobile));
    }

    @GetMapping("/info/{id}")
    @ApiOperation(value = "根据id获取分销员钱包流水信息")
    @ApiImplicitParam(name = "id", value = "分销员钱包流水id", dataType = "Long")
    public ServerResponseEntity<DistributionUserWalletBill> getById(@PathVariable("id") Long id) {
        return ServerResponseEntity.success(distributionUserWalletBillService.getById(id));
    }

    @PostMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserWalletBill:save')")
    @ApiOperation(value = "新增分销员钱包流水")
    public ServerResponseEntity<Boolean> save(@RequestBody @Valid DistributionUserWalletBill distributionUserWalletBill) {
        return ServerResponseEntity.success(distributionUserWalletBillService.save(distributionUserWalletBill));
    }

    @PutMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserWalletBill:update')")
    @ApiOperation(value = "修改分销员钱包流水")
    public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid DistributionUserWalletBill distributionUserWalletBill) {
        return ServerResponseEntity.success(distributionUserWalletBillService.updateById(distributionUserWalletBill));
    }

    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserWalletBill:delete')")
    @ApiOperation(value = "根据id删除分销员钱包流水")
    @ApiImplicitParam(name = "id", value = "分销员钱包流水id", dataType = "Long")
    public ServerResponseEntity<Boolean> removeById(@PathVariable Long id) {
        return ServerResponseEntity.success(distributionUserWalletBillService.removeById(id));
    }
}
